package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class RegDemo {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
//        Class.forName("com.mysql.cj.jdbc.Driver");
//        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true", "root", "root");
        Connection conn = DBUtil.getConnection();
        Statement statement = conn.createStatement();
//        Scanner scan = new Scanner(System.in);
//        System.out.println("请输入您的用户名,密码，昵称和年龄：");
//        String a = scan.nextLine();
//        String b = scan.nextLine();
//        String c = scan.nextLine();
//        int d = scan.nextInt();
//        String sql = "INSERT INTO userinfo(username,password,nickname,age) VALUES('"+a+"','"+b+"','"+c+"',"+d+")";
//        int num = statement.executeUpdate(sql);
//        conn.close();
        UserInfo userInfo = InputUtil.getInputObject(new UserInfo(), "欢迎注册");
        String sql = "INSERT INTO userinfo(username,password,nickname,age)" + "VALUES('" + userInfo.getUsername() + "','" + userInfo.getPassword() + "','" + userInfo.getNickname() + "'," + userInfo.getAge() + ")";
        int num = statement.executeUpdate(sql);
        System.out.println(num>0?"注册成功":"注册失败");
        conn.close();
    }
}
